﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SCGILite.SCgi;
using SCGILite.NetLib;
using SCGILite.Helper;
using System.IO;
using System.Globalization;

namespace SCGITest
{
    class DemoSCGISession: SCgiSession
    {
        public DemoSCGISession(ISocketSession tcp)
            : base(tcp)
        {
        }

        #region ResponseHeaders
        public void ResponseHeaders(IDictionary<string, string> headers, int statuesCode, int bodyLen)
        {
            if (headers == null)
                headers = new Dictionary<string, string>();
            headers["Content-Type"] = "text/html; charset=utf-8";
            headers["Server"] = "YxjWeb/1.0.11";
            if (bodyLen >= 0)
                headers["Content-Length"] = bodyLen.ToString();
            this.StatuesCode = statuesCode;
            this.ResponseHeaders(headers);
        }
        #endregion

        public override void OnSCgiBodyReady()
        {
            OnBody(this);
        }
        public override void OnSCgiHeaderReady()
        {
            //throw new Exception();
        }

        public override void OnErr(Exception e)
        {
            OnException(this, e);
        }

        public Action<DemoSCGISession, Exception> OnException = null;
        public Action<DemoSCGISession> OnBody = null;
    }
}
